#include <iostream>
#include "Tour.h"
using namespace std;
Tour::Tour()
{
}

Tour::Tour(int x,int y, bool white)
{
    m_x = x;
    m_y = y;
    m_white = white;

}

bool
Tour::mouvementvalide(Echiquier *e, int x, int y )
{
    if(Piece::mouvementvalide(e,x,y))
    {
        bool valide = true;
        int i = 1;
        if (y > m_y && x == m_x)
        {
            while(i <= y-m_y && valide)
            {
                if(e->getPiece(m_x,m_y - i) == 0)
                    i++;
                else
                    valide = false;
            }
            return valide;
        }
        else if (x > m_x && y == m_y)
        {
            while(i <= x-m_x && valide)
            {
                if(e->getPiece(m_x + i,m_y) == 0)
                    i++;
                else
                    valide = false;
            }
            return valide;
        }

        else if (x < m_x && y == m_y)
        {
            while(i >= m_y-y && valide)
            {
                if(e->getPiece(m_x - i,m_y) == 0)
                    i++;
                else
                    valide = false;
            }
            return valide;
        }

        if (y < m_y && x == m_x)
        {
            while(i <= m_y - y && valide)
            {
                if(e->getPiece(m_x,m_y - i) == 0)
                    i++;
                else
                    valide = false;
            }
            return valide;
        }
        else
            return false;
    }
    else
        return false;
}

void
Tour::affiche()
{
    cout << "Tour: x=" << m_x << " y=" << m_y << " "
         << ( isWhite() ? "blanche" : "noire" ) << endl;

}


char Tour::tostring()
{
    return( isWhite() ? 'T' : 't');
}
Tour::~Tour(){}
